local UI = SecretaryUI

local function GetTableObject(this)
	return this:GetParent():GetParent().object
end

local function Cell_OnClick(this)
	GetTableObject(this):OnCellClick(this.col, this.row)
end

local function Cell_OnDoubleClick(this)
	GetTableObject(this):OnCellDoubleClick(this.col, this.row)
end

local function Cell_OnEnter(this)
	GetTableObject(this):OnCellEnter(this.col, this.row)
end

local function Cell_OnLeave(this)
	GetTableObject(this):OnCellLeave(this.col, this.row)
end

local function MakeCell(parent, row, col)
	local cell = CreateFrame("Button", parent:GetName().."Cell_"..row.."_"..col, parent)
	
	cell:EnableMouse(true)
	cell:RegisterForClicks("LeftButton")
	cell:SetTextFontObject("GameFontNormalSmall")

	cell.row, cell.col = row, col

	cell:SetScript("OnDoubleClick", Cell_OnDoubleClick)
	cell:SetScript("OnClick", Cell_OnClick)
	cell:SetScript("OnEnter", Cell_OnEnter)
	cell:SetScript("OnLeave", Cell_OnLeave)
	
	return cell
end

UI.MakeCell = MakeCell
